/*
 * This file is part of quickReminder, a software for gamers
 *
 * Copyright (C) 2006-2008 Lucas Romero
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
using System;
using System.Collections.Generic;
using System.Text;
using LucasCode.Win32;

namespace UserNotifier
{
    public class HWBeepWarnModule : WarnModule
    {
        private HWBeepNote[] m_Notes;

        public HWBeepNote[] Notes
        {
            get { return m_Notes; }
            set { m_Notes = value; }
        }
        public HWBeepWarnModule(int interval, int frequency, int duration)
            : this(interval, new HWBeepNote[] { new HWBeepNote(frequency, duration) })
        {
            //nothing
        }
        public HWBeepWarnModule(int interval, HWBeepNote[] notes)
            : base(interval)
        {
            m_Notes = notes;
        }

        public HWBeepWarnModule()
            : base()
        {
            
        }

        public override string Description
        {
            get
            {
                return Info.HWBeepDesc;
            }
        }

        public override WarnModuleTypes Type
        {
            get { return WarnModuleTypes.HWBeepWarnModule; }
        }

        protected override void Warn()
        {
            PlayNotes(m_Notes);
        }

        private void PlayNotes(HWBeepNote[] notes)
        {
            foreach (HWBeepNote n in notes)
            {
                if (n.Frequency > 0)
                {
                    Kernel32.Beep(n.Frequency, n.Duration);
                    System.Threading.Thread.Sleep(50);
                }
                else
                    System.Threading.Thread.Sleep(n.Duration);
            }
        }

        /*public override void Test()
        {
            int sl = 250;
            int ln = 500;
            List<HWBeepNote> ame = new List<HWBeepNote>();
            ame.Add(new HWBeepNote(HWBeepNotes.C, sl));
            ame.Add(new HWBeepNote(HWBeepNotes.D, sl));
            ame.Add(new HWBeepNote(HWBeepNotes.E, sl));
            ame.Add(new HWBeepNote(HWBeepNotes.F, sl));
            ame.Add(new HWBeepNote(HWBeepNotes.G, ln));
            ame.Add(new HWBeepNote(HWBeepNotes.G, ln));
            ame.Add(new HWBeepNote(HWBeepNotes.A, sl));
            ame.Add(new HWBeepNote(HWBeepNotes.A, sl));
            ame.Add(new HWBeepNote(HWBeepNotes.A, sl));
            ame.Add(new HWBeepNote(HWBeepNotes.A, sl));
            ame.Add(new HWBeepNote(HWBeepNotes.G, ln));
            ame.Add(new HWBeepNote(HWBeepNotes.Pause, sl));

            ame.Add(new HWBeepNote(HWBeepNotes.A, sl));
            ame.Add(new HWBeepNote(HWBeepNotes.A, sl));
            ame.Add(new HWBeepNote(HWBeepNotes.A, sl));
            ame.Add(new HWBeepNote(HWBeepNotes.A, sl));
            ame.Add(new HWBeepNote(HWBeepNotes.G, ln));
            ame.Add(new HWBeepNote(HWBeepNotes.Pause, sl));

            ame.Add(new HWBeepNote(HWBeepNotes.F, sl));
            ame.Add(new HWBeepNote(HWBeepNotes.F, sl));
            ame.Add(new HWBeepNote(HWBeepNotes.F, sl));
            ame.Add(new HWBeepNote(HWBeepNotes.F, sl));
            ame.Add(new HWBeepNote(HWBeepNotes.E, ln));
            ame.Add(new HWBeepNote(HWBeepNotes.E, ln));

            ame.Add(new HWBeepNote(HWBeepNotes.D, sl));
            ame.Add(new HWBeepNote(HWBeepNotes.D, sl));
            ame.Add(new HWBeepNote(HWBeepNotes.D, sl));
            ame.Add(new HWBeepNote(HWBeepNotes.D, sl));
            ame.Add(new HWBeepNote(HWBeepNotes.C, 1000));
            //bool old = Warning;
            //Warning = true;
            PlayNotes(ame.ToArray());
            //Warning = old;
        }*/
    }
}
